Skip to content

Resolve pm2 ports from listening sockets instead of env vars#29

Merged
fredrivett merged 2 commits into
mainfrom
fredrivett/test-real-pm2-instance
Jun 26, 2026
Merged

Resolve pm2 ports from listening sockets instead of env vars#29
fredrivett merged 2 commits into
mainfrom
fredrivett/test-real-pm2-instance

Conversation

@fredrivett

@fredrivett fredrivett commented Jun 26, 2026

Copy link
Copy Markdown
Owner

Port detection previously read the bare PORT or any *_PORT env var from pm2_env, which inside Conductor latched onto the inherited CONDUCTOR_PORT allocation — overriding an app's real port and giving non-server processes a phantom one. This replaces the heuristic with SocketScanner, which resolves each process's ports from the actual listening sockets (one lsof + one ps per refresh, machine-wide) and attributes ports opened by child processes too, so npm-wrapped servers (pm2 start npm -- run dev) resolve correctly. PM2Process.port (Int?) becomes ports ([Int]): the row shows up to two ports as links with a +N overflow badge and a tooltip listing all, while the env header keeps its band/range aggregated over the real ports. The decoder no longer enumerates pm2_env at all, IPv4/IPv6 bindings collapse, and debug/inspector ports (9229–9231) are filtered. Adds a pure PortDisplay helper and tests covering socket parsing, process-tree resolution, debug filtering, and the display logic.

🤖 Generated with Claude Code


Summary by cubic

Resolve PM2 ports from actual listening sockets instead of env vars to prevent phantom ports and correctly attribute child process listeners; the UI now shows up to two ports with a +N overflow and the env header aggregates real port ranges.

  • Bug Fixes

    • Stop reading PORT/*_PORT from pm2_env; use SocketScanner (one lsof + one ps per refresh) to map ports by pid and descendants. Fixes CONDUCTOR_PORT bleed-through and npm-wrapped servers.
    • Collapse IPv4/IPv6 duplicates and filter debug ports 9229–9231.
  • Refactors

    • Replace PM2Process.port with ports: [Int]; update search, env header band/range, and rows via ProcessPortsView (shows up to two ports with a +N tooltip).
    • Add pure PortDisplay helper and tests for socket parsing, process-tree resolution, debug filtering, and display logic; decoder no longer enumerates pm2_env.

Written for commit 74a8373. Summary will update on new commits.

Review in cubic

fredrivett and others added 2 commits June 26, 2026 14:32
Port detection previously read the bare PORT or any *_PORT env var from
pm2_env, preferring a specific *_PORT over PORT. Inside Conductor this
latched onto the inherited CONDUCTOR_PORT allocation: it overrode an app's
real PORT and gave non-server processes a phantom port. The env var is only
intent; the listening socket is truth.

Replace the heuristic with SocketScanner, which snapshots the machine once
per refresh (one lsof + one ps) and resolves each process's ports from its
own pid plus descendants — so npm-wrapped servers (pm2 start npm -- run dev),
where the real listener is a child, are attributed correctly. IPv4/IPv6
bindings collapse, debug/inspector ports (9229-9231) are filtered, and the
decoder no longer enumerates pm2_env at all.

PM2Process.port (Int?) becomes ports ([Int]). The row shows up to two ports
with a +N overflow badge and a tooltip listing all; the env header keeps its
band/range, now aggregating the flattened real ports.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Extract the row's "up to two ports, then +N" decision out of ProcessPortsView
into a pure PortDisplay.summarize helper so it can be unit-tested, and cover
it (0/1/2/3/many ports, custom limit, tooltip lists all).

Add robustness tests for the socket parsers: orphan name lines, wildcard /
non-numeric port tails, unrecognised lsof field tags, malformed ps lines, and
a combined debug-filter-plus-sort case.

Drop a redundant inline comment in PM2Process decoding (the same fact is
already on the ports property and the extension header).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 9 files

Re-trigger cubic

@fredrivett fredrivett merged commit 3aea456 into main Jun 26, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant